/*
 * Powered By [Frank-Liz-Lee]
 * Copyright(C) 2012-2016 Liz Company
 * All rights reserved.
 */

package com.linln.modules.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.modules.system.mapper.ActionLogMapper;
import com.linln.modules.system.domain.ActionLog;
import java.util.List;

import com.linln.modules.system.service.ActionLogService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor = Exception.class)
@Service
public class ActionLogServiceImpl  extends GenericService<ActionLog, Long>  implements ActionLogService {

    private ActionLogMapper actionLogMapper;

    @Autowired
    public void setActionLogMapper(ActionLogMapper actionLogMapper) {
        this.actionLogMapper = actionLogMapper;
    }

    /**
     * 通过主键查询实体对象
     * @param primaryKey
     * @return
     * @
     */
    public ActionLog getByPK(Long primaryKey)  {
        return actionLogMapper.getByPK(primaryKey);
    }

    /**
     * 查询所有记录
     * @return
     * @
     */
    public List<ActionLog> list()  {
        return actionLogMapper.list();
    }

    /**
     * 根据查询条件查询所有记录
     * @return
     * @
     */
    public List<ActionLog> listByProperty(ActionLog actionLog) {
        return actionLogMapper.listByProperty(actionLog);
    }


    /**
     * 根据主键删除记录
     * @param primaryKey
     * @return
     * @
     */
    public int deleteByPK(Long primaryKey)  {
        return actionLogMapper.deleteByPK(primaryKey);
    }

    /**
     * 根据多个主键删除记录
     * @param primaryKeys
     * @
     */
    public int deleteByPKeys(List<Long> primaryKeys)  {
        return actionLogMapper.deleteByPKeys(primaryKeys);
    }

    /**
     * 根据传入参数删除记录
     * @param actionLog
     * @return
     * @
     */
    public int deleteByProperty(ActionLog actionLog)  {
        return actionLogMapper.deleteByProperty(actionLog);
    }

    /**
     * 保存记录
     * @param actionLog
     * @return
     * @
     */
    public int save(ActionLog actionLog)  {
        return actionLogMapper.save(actionLog);
    }

    /**
     * 更新记录
     * @param actionLog
     * @return
     * @
     */
    public int update(ActionLog actionLog) {
        return actionLogMapper.update(actionLog);
    }

    /**
     * 根据条件查询记录条数
     * @param actionLog
     * @return
     * @
     */
    public int findByCount(ActionLog actionLog)  {
        return actionLogMapper.findByCount(actionLog);
    }

    /**
     * 根据查询条件查询分页记录
     * @return
     */
    public PageInfo<ActionLog> findByPage(Integer pageNum, Integer pageSize, ActionLog actionLog) {
        PageHelper.startPage(pageNum,pageSize);
        List<ActionLog> actionLogList = actionLogMapper.listByProperty(actionLog);
        if(null == actionLogList || actionLogList.size() == 0){
            return new Page<ActionLog>().toPageInfo();
        }
        Page<ActionLog> page =  (Page<ActionLog>)actionLogList;
            return page.toPageInfo();
    }

    @Override
    public List<ActionLog> getDataLogList(String tableName, Long entityId) {
        ActionLog temp = new ActionLog();
        temp.setModel(tableName);
        temp.setRecordId(entityId);
        return actionLogMapper.listByProperty(temp);
    }


    @Override
    public void emptyLog() {
        actionLogMapper.deleteAll();
    }
}
